package com.example.project.manageController;

import com.example.project.dao.AdminDAO;
import com.example.project.pojo.Admin;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("manage")
public class ManageLoginController {
    @RequestMapping("loginCheck")
    public String loginCheck(Admin admin, HttpServletRequest request) {
        AdminDAO adminDAO = new AdminDAO();
        Admin admin1 = adminDAO.login(admin);
        if (admin1.getAdminUserName().isEmpty()) {

            return "redirect:/web/login?msg=2";

        }
        HttpSession httpSession = request.getSession();
        httpSession.setAttribute("admin", admin1);
        return "redirect:/manage/index";

    }
}

